﻿<Window x:Class="MiniUML.Diagnostics.ExceptionDialogWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:MiniUML.Diagnostics"
        MinHeight="245" MaxHeight="440" SizeToContent="WidthAndHeight" ResizeMode="NoResize"
        WindowStartupLocation="CenterOwner" ShowInTaskbar="False" WindowState="Normal" Icon="{DynamicResource ApplicationIcon}">

    <Window.Resources>

        <DataTemplate DataType="{x:Type system:Exception}">

            <DataTemplate.Resources>
                <local:ExceptionTypeConverter x:Key="exceptionTypeConverter" />
            </DataTemplate.Resources>

            <Grid Margin="1,3,3,3" Background="White">

                <Border x:Name="itemBorder"
                        SnapsToDevicePixels="True"
                        BorderThickness="1"
                        BorderBrush="#FFDFDFDF"
                        Background="#FFF0F0F0">

                    <Grid Margin="10,5,10,5">

                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100"/>                            <ColumnDefinition Width="300"/>
                            <ColumnDefinition Width="100"/>
                        </Grid.ColumnDefinitions>

                        <TextBlock Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="1" Margin="0,2,0,0"
                                   Foreground="Gray" FontSize="9" TextAlignment="Right" TextWrapping="Wrap"
                                   Text="{Binding Path=Data[ExceptionManager.Timestamp]}"/>

                        <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Margin="0,0,0,0"
                                   Foreground="Black" FontSize="11" FontWeight="Bold" TextWrapping="Wrap"
                                   Text="{Binding Converter={StaticResource exceptionTypeConverter}}"/>

                        <TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="0,2,0,0"
                                   Foreground="Black" FontSize="11" TextWrapping="Wrap"
                                   Text="{Binding Path=Message}"/>

                        <TextBlock Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="1" Margin="0,5,0,0"
                                   Foreground="Gray" FontSize="11" TextWrapping="Wrap"
                                   Text="Message:"/>

                        <TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,5,0,0"
                                   Foreground="Black" FontSize="11" TextWrapping="Wrap"
                                   Text="{Binding Path=Data[ExceptionManager.Message]}"/>

                        <TextBlock Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="1" Margin="0,5,0,0"
                                   Foreground="Gray" FontSize="11" TextWrapping="Wrap"
                                   Text="Recovery action:"/>

                        <TextBlock x:Name="recoveryAction" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="1" Margin="0,5,0,0"
                                   Foreground="Black" FontSize="11" TextWrapping="Wrap"
                                   Text="{Binding Path=Data[ExceptionManager.RecoveryAction]}"/>
                    </Grid>

                </Border>

            </Grid>

            <DataTemplate.Triggers>

                <DataTrigger Binding="{Binding Path=Data[ExceptionManager.HasBeenShown]}" Value="True">
                    <Setter TargetName="itemBorder" Property="Opacity" Value="0.5"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Path=Data[ExceptionManager.IsCritical]}" Value="True">
                    <Setter TargetName="itemBorder" Property="Background" Value="#FFF0EAEA"/>
                    <Setter TargetName="recoveryAction" Property="Text" Value="Unable to recover; program must be closed."/>
                </DataTrigger>

            </DataTemplate.Triggers>

        </DataTemplate>

    </Window.Resources>

    <Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <TextBlock Grid.Row="0" Margin="10,10,10,0" Foreground="#FF003399" FontSize="16" Text="One or more errors have occured"/>
        <TextBlock Grid.Row="1" Margin="10,16,10,0" Text="The following exceptions were handled:"/>
        <ListBox Grid.Row="2"
                 Margin="10,5,10,16"
                 Padding="2"
                 SnapsToDevicePixels="True"
                 BorderThickness="1"
                 BorderBrush="#FFDFDFDF"
                 HorizontalContentAlignment="Stretch"
                 ItemsSource="{Binding Source={x:Static local:ExceptionManager.Exceptions}}"/>

        <Border Grid.Row="3"
                Padding="3,0,3,1"
                SnapsToDevicePixels="True"
                BorderThickness="0,1,0,0"
                BorderBrush="#FFDFDFDF"
                Background="#FFF0F0F0">

            <StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
                <Button x:Name="button" Margin="8" Padding="15,0,15,0" IsDefault="True" Content="Continue" Click="_button_Click"/>
            </StackPanel>

        </Border>

    </Grid>

</Window>